package com.dabaozhan.common.utils.aliyun.ocr;

import java.util.HashMap;
import java.util.Map;

import com.dabaozhan.common.utils.aliyun.api.util.HttpUtils;
import org.apache.http.util.EntityUtils;
import com.alibaba.fastjson.JSONObject;

public class BankCardutils {
    
	/**
	 * 银行卡信息填写
	 * @param querys
	 * @return
	 * @throws Exception
	 */
    public static JSONObject getBankCard(Map<String, String> querys) throws Exception {
    	JSONObject dataValueObj = null;
    	String host = "https://b4bankcard.market.alicloudapi.com";
	    String path = "/bank4Check";
	    String method = "GET";
	    String appcode = "415ad20123d2416d918f86cfdde1ffbb";
	    Map<String, String> headers = new HashMap<String, String>();
	    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
	    headers.put("Authorization", "APPCODE " + appcode);
	    try {
	    	org.apache.http.HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
	    	
	    	dataValueObj = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
    	return dataValueObj;
    }
    
    public static void main(String[] args) throws Exception {
	    String host = "https://b4bankcard.market.alicloudapi.com";
	    String path = "/bank4Check";
	    String method = "GET";
	    String appcode = "415ad20123d2416d918f86cfdde1ffbb";
	    Map<String, String> headers = new HashMap<String, String>();
	    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
	    headers.put("Authorization", "APPCODE " + appcode);
	    
	    Map<String, String> querys = new HashMap<String, String>();
	    /*querys.put("accountNo", "6217002000051966036");
	    querys.put("idCard", "412726199407224120");
	    querys.put("mobile", "15736882420");
	    querys.put("name", "刘春艳");*/
//	    querys.put("accountNo", "6225750803745872");
//	    querys.put("idCard", "421125198708043339");
//	    querys.put("mobile", "13222295954");
//	    querys.put("name", "王喜亮");

		querys.put("accountNo", "6217002000043544255");
	    querys.put("idCard", "340822199008234321");
	    querys.put("mobile", "18944226830");
	    querys.put("name", "冯慧珍");

		//&bankName=冯慧珍
		// &cardNumber=340822199008234321
		// &bankCardNumber=6217002000043544255
		// &phone=18944226830
	    
//	    querys.put("accountNo", "6225882137262876");
//	    querys.put("idCard", "430122199005171816");
//	    querys.put("mobile", "18608404525");
//	    querys.put("name", "侯忠");
	    JSONObject dataValueObj = BankCardutils.getBankCard(querys);
	    System.out.println(dataValueObj);
	    
             //JDK 1.8示例代码请在这里下载：  http://code.fegine.com/Tools.zip

	    /*try {
	    	org.apache.http.HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
	    	//System.out.println(response.toString());如不输出json, 请打开这行代码，打印调试头部状态码。
                //状态码: 200 正常；400 URL无效；401 appCode错误； 403 次数用完； 500 API网管错误
	    	//获取response的body
	    	//System.out.println(EntityUtils.toString(response.getEntity()));
	    	
	    	JSONObject dataValueObj = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
	    	System.out.println(dataValueObj);
 	    	//获取数据
 	    	String result = dataValueObj.getString("accountNo");
 	    	String status = dataValueObj.getString("status");
 	    	System.out.println(result);
 	    	System.out.println(status);
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }*/
	}
}
